<template>
	<view>
		<text>云储存</text>
		<button type="default" @click="handle">上传</button>
		<image :src="src" mode="aspectFit"></image>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				src: ''
			}
		},
		methods: {
			handle() {
				// uniCloud.deleteFile({
				// 	fileList:["https://vkceyugu.cdn.bspapp.com/VKCEYUGU-0e774c48-ffe9-4a1b-a59c-265f0b93e2ef/2286c483-b366-49a1-9e5d-fc83c5b738f6.png"]
				// })
				uni.chooseImage({
					success: async res => {
						if (res.tempFilePaths.length > 0) {
							const filePath = res.tempFilePaths[0];
							console.log(res)
							const result = await uniCloud.uploadFile({
								filePath: filePath,
								cloudPath: res.tempFiles[0].name,
								onUploadProgress: function(progressEvent) {
									console.log(progressEvent);
									var percentCompleted = Math.round(
										(progressEvent.loaded * 100) / progressEvent.total);
								}
							});
							console.log('上传返回：', result)
							uniCloud.getTempFileURL({
								fileList: [result.fileID]
							}).then(res => {
								console.log('获取临时地址：', res);
								this.src = res.fileList[0].tempFileURL
							});
						}
					}
				})
			}
		}
	}
</script>
<style>
</style>
